#pragma once
#include "../windows.h"

namespace acme {
  namespace scratch {
    using namespace acme::windows;

// A simple class for writing formatted output to the windows console.
// why not printf? Because this is UNICODE compatible.
class Console
{
  HANDLE hStdOut;
public:
  Console()
  {
    hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  }
  int Write(LPCWSTR str)
  {
    DWORD dw;
    WriteConsoleW(hStdOut,str,lstrlenW(str),&dw,NULL);
    return dw;
  }
  int WriteFormat(LPCWSTR format, ...)
  {
    va_list arglist;
    va_start(arglist,format);
    WCHAR buf[1025];
    int cch = wvsprintf(buf,format,arglist);
    DWORD dw;
    WriteConsoleW(hStdOut,buf,cch,&dw,NULL);

    va_end(arglist);
    return dw;
  }
  int WriteFormat(LPCSTR format, ...)
  {
    va_list arglist;
    va_start(arglist,format);
    CHAR buf[1025];
    int cch = wvsprintfA(buf,format,arglist);
    DWORD dw;
    WriteConsoleA(hStdOut,buf,cch,&dw,NULL);

    va_end(arglist);
    return dw;
  }

};

  }
}